<?php
	echo $this->Html->css(array('jquery.ui.button','jquery.ui.position','jquery.ui.autocomplete'));
	echo $this->Html->script(array('jquery.ui.button','jquery.ui.position','jquery.ui.autocomplete','autocombo')); 
?>
<style>
	.ui-autocomplete {
		max-height: 100px;
		overflow-y: auto;
		/* prevent horizontal scrollbar */
		overflow-x: hidden;
		/* add padding to account for vertical scrollbar */
		padding-right: 20px;
	}
	/* IE 6 doesn't support max-height
	 * we use height instead, but this forces the menu to always be this tall
	 */
	* html .ui-autocomplete {
		height: 100px;
	}
	</style>
<script>
	$(function() {
		$("#dausach_id").combobox();
		$(".so").keydown(function(e) {
			arr_key = new Array();
			arr_key[8]=8;
			arr_key[9]=9;
			arr_key[35]=35;
			arr_key[36]=36;
			arr_key[37]=37;
			arr_key[39]=39;
			arr_key[46]=46;
	        if ( arr_key[e.keyCode]!==undefined) {}
	        else {
	            if (e.keyCode < 48 || e.keyCode > 57 ) {
	                e.preventDefault(); 
	            }   
	        }
	    });

		/*
		 $("#dongia").keyup(function(e) {
		 			$(this).val(numberformat($(this).val()));
		 
	    });*/
	});

	

	function validate()
	{
		if($("#dausach_id" ).val()=='')
		{
			alert('Bạn chưa chọn đầu sách nhập');
			return false;
		}
		if($("#soluong" ).val()=='')
		{
			alert('Bạn chưa nhập số lượng sách nhập');
			$("#soluong" ).focus();
			return false;
		}
		if($("#dongia" ).val()=='')
		{
			alert('Bạn chưa nhập đơn giá');
			$("#dongia" ).focus();
			return false;
		}		
		return true;
	}
</script>
<div class="index">
<h2  style='text-align: center'>Chi tiết hóa đơn nhập</h2>
<p><strong>Số hóa đơn:</strong> <?php echo $this->data['Hoadonnhap']['sohd']?></p>
<p><strong>Ngày nhập:</strong> <?php echo date('d-m-Y',strtotime($this->data['Hoadonnhap']['ngaynhap']));?></p>
<p><strong>Nhân viên:</strong> <?php echo $this->data['Nhanvien']['masonv'].' - '.$this->data['Nhanvien']['tennv']?></p>
<br>
<table id='tables' id='tables'>
<tr>
<th>STT</th>
<th>Mã Sách</th>
<th>Tên sách</th>
<th>Số lượng</th>
<th>Đơn giá (VNĐ)</th>
<th>Số cuốn giữ lại</th>
<th>Thao tác</th>
</tr>
<?php 
echo $form->create('Chitietnhap',array('onsubmit'=>'return validate()','url'=>array('controller'=>'chitietnhaps','action'=>'dausachnhap',$id)));
$i= 0;
foreach ($chitietnhaps as $chitietnhap):
?>
<tr>
<td><?php echo ++$i?></td>
<td><?php echo $chitietnhap['Dausach']['mads']?></td>
<td><?php echo $chitietnhap['Dausach']['tensach']?></td>
<td><?php echo $chitietnhap['Chitietnhap']['soluong']?></td>
<td><?php echo number_format($chitietnhap['Chitietnhap']['dongia'],0,',','.');?></td>
<td></td>
</tr>
<?php endforeach;?>
<tr>
<td><?php echo ++$i?></td>
<td></td>
<td><?php echo $form->input('dausach_id',array('id'=>'dausach_id','label'=>false,'type'=>'select','options'=>$dausaches,'empty'=>''));?></td>
<td><?php echo $form->input('soluong',array('id'=>'soluong','class'=>'so','label'=>false,'type'=>'text'));?></td>
<td><?php echo $form->input('dongia',array('id'=>'dongia','class'=>'so','label'=>false,'type'=>'text'));?></td>
<td><?php echo $form->input('socuon',array('id'=>'socuon','label'=>false,'type'=>'text','value'=>0));?></td>
<td><?php echo $form->submit('Lưu',array('id'=>'idsub'));?></td>
</tr>
</table>
</div>